package com.ctgu.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctgu.springboot.common.QueryPageParam;
import com.ctgu.springboot.entity.Team;
import com.ctgu.springboot.mapper.TeamMapper;
import com.ctgu.springboot.service.TeamService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wms
 * @since 2023-02-16
 */
@Service
public class TeamServiceImpl extends ServiceImpl<TeamMapper, Team> implements TeamService {

    @Resource
    private TeamMapper teamMapper;

    @Override
    public IPage<Team> teamPage(QueryPageParam query) {

        Integer id = (Integer) query.getParam().get("team_id");
        String name = (String) query.getParam().get("team_name");
        Integer traId = (Integer) query.getParam().get("tra_id");

        Page<Team> page = new Page<>();
        page.setCurrent(query.getPageNum());
        page.setSize(query.getPageSize());

        LambdaQueryWrapper<Team> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (id!=null) {
            lambdaQueryWrapper.like(Team::getTeamId, id);
        }
        if (StringUtils.isNotBlank(name) && !"null".equals(name)) {
            lambdaQueryWrapper.like(Team::getTeamName, name);
        }
        if (traId!=null) {
            lambdaQueryWrapper.eq(Team::getTraId, traId);
        }
        return teamMapper.teamPage(page, lambdaQueryWrapper);
    }

    @Override
    public List<Team> getList(){
        return teamMapper.getList();
    }
}
